package edu.netjava.BiLinkList;

public class BiLinkListTest {
	/**
	 * @param args
	 *            :the parameter for application
	 */
	public static void main(String[] args) {

		/**
		 * 
		 */
		BiLinkList lkl = new BiLinkList();
		lkl.add("a");
		lkl.add("b");
		lkl.add("c");
		lkl.printAll();
		// lkl.printFromTail();

		String str;
		int choice;
		java.util.Scanner sca = new java.util.Scanner(System.in);
		boolean isExit = false;
		while (!isExit) {

			System.out.println("Please input the element:");
			String element = sca.next();
			lkl.add(element);
			System.out.println("Do you want to continue to input?y/n");
			str = sca.next();
			if (str.equalsIgnoreCase("n")) {
				isExit = true;
			}

		}

		isExit = false;
		while (!isExit) {
			System.out.println("Please give out your choice below:\n"
					+ "B,print elements\n" + "C,delete element\n"
					+ "D,find the element\n" + "E,print from tail\n"
					+ "F,insert element\n" + "Q,exit!");
			str = sca.next();
			if (str.equalsIgnoreCase("B")) {

				System.out.println("all of the elements are:");
				System.out.println("-----------------------------");
				lkl.printAll();
				System.out.println("-----------------------------");

			} else if (str.equalsIgnoreCase("C")) {

				System.out.println("Please give out the index of the element:");
				choice = sca.nextInt();
				lkl.delete(choice);
				System.out.println("the element locate at" + choice
						+ "has been delete!");

			} else if (str.equalsIgnoreCase("D")) {

				System.out.println("Please give out the index of the element:");
				choice = sca.nextInt();
				System.out.println("This is the element you're looking for:");
				System.out.println("====================");
				System.out.println(lkl.findNode(choice));
				System.out.println("====================");
			} else if (str.equalsIgnoreCase("E")) {

				System.out.println("Now print the list from tail!");
				lkl.printFromTail();

			} else if (str.equalsIgnoreCase("F")) {

				System.out
						.println("Please input the index of the inserting element:");
				choice = sca.nextInt();
				System.out.println("Please input the value of the element:");
				str = sca.next();
				lkl.insertNode(choice, str);
			} else if (str.equalsIgnoreCase("Q")) {
				isExit = true;
				System.out.println("the operation is over!");
			}
		}

		// Node node = new Node();
		// System.out.println(node);

	}

}
